package org.samcolon.eeexplore.utils;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.date.LocalDateTimeUtil;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.event.AnalysisEventListener;
import com.alibaba.excel.metadata.CellData;
import com.alibaba.excel.metadata.Head;
import com.alibaba.excel.write.builder.ExcelWriterBuilder;
import com.alibaba.excel.write.metadata.holder.WriteSheetHolder;
import com.alibaba.excel.write.metadata.style.WriteCellStyle;
import com.alibaba.excel.write.metadata.style.WriteFont;
import com.alibaba.excel.write.style.HorizontalCellStyleStrategy;
import com.alibaba.excel.write.style.column.AbstractColumnWidthStyleStrategy;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.HorizontalAlignment;
import org.apache.poi.ss.usermodel.IndexedColors;
import org.apache.poi.ss.usermodel.VerticalAlignment;
import org.samcolon.eeexplore.vo.DetailRecordVO;

import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.lang.reflect.Field;
import java.net.URLEncoder;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.*;

@Slf4j
public class EasyExcel2Util {

    /**
     * 导出Excel
     *
     * @param response
     * @param clazz    Excel的表头对象
     * @param data     Excel的内容集合
     * @param fileName 文件名
     * @throws Exception
     */
    public static void downLoadExcel(HttpServletResponse response, Class<?> clazz, List<?> data, String fileName) throws Exception {
        downLoadExcel(response, clazz, data, fileName, null);
    }


    public static void downLoadExcelDynamic(HttpServletResponse response, Class<?> clazz, List<?> data, String fileName, List<String> includColumns) throws Exception {
        downLoadExcelDynamic(response, clazz, data, fileName, includColumns, null);
    }

    public static void downLoadExcelDynamicInclude(HttpServletResponse response, Class<?> clazz, List<?> data, String fileName, String... includColumns) throws Exception {
        downLoadExcelDynamic(response, clazz, data, fileName,
                ArrayUtil.isNotEmpty(includColumns) ? CollUtil.newArrayList(includColumns) : null, null);
    }

    public static void downLoadExcelDynamicExclude(HttpServletResponse response, Class<?> clazz, List<?> data, String fileName, String... excludeColumn) throws Exception {
        downLoadExcelDynamic(response, clazz, data, fileName, null,
                ArrayUtil.isNotEmpty(excludeColumn) ? CollUtil.newArrayList(excludeColumn) : null);
    }

    public static void downLoadExcelDynamic(HttpServletResponse response, Class<?> clazz, List<?> data, String fileName, List<String> includColumns, List<String> excludeColumn) throws Exception {
        response.setContentType("application/vnd.ms-excel");
        response.setCharacterEncoding("utf-8");
        response.setHeader("Content-disposition", "attachment;filename=" + URLEncoder.encode(fileName, "UTF-8") + ".xlsx");
        ExcelWriterBuilder excelWriterBuilder = EasyExcel.write(response.getOutputStream(), clazz);
        excelWriterBuilder.useDefaultStyle(false);
        if (CollUtil.isNotEmpty(includColumns)) {
            excelWriterBuilder.includeColumnFiledNames(includColumns);
        }
        if (CollUtil.isNotEmpty(excludeColumn)) {
            excelWriterBuilder.excludeColumnFiledNames(excludeColumn);
        }

        excelWriterBuilder.registerWriteHandler(new Custemhandler());
        excelWriterBuilder.registerWriteHandler(getStyleStrategy());
        excelWriterBuilder.build().write(data, EasyExcel.writerSheet("sheet").build()).finish();
    }

    public static void downLoadExcelDynamic(OutputStream output, Class<?> clazz, List<?> data) throws Exception {
        downLoadExcelDynamic(output, clazz, data, "", null, null);

    }

    public static void downLoadExcelDynamic(OutputStream output, Class<?> clazz, List<?> data, String fileName, List<String> includColumns, List<String> excludeColumn) throws Exception {
        ExcelWriterBuilder excelWriterBuilder = EasyExcel.write(output, clazz);
        excelWriterBuilder.useDefaultStyle(false);
        if (CollUtil.isNotEmpty(includColumns)) {
            excelWriterBuilder.includeColumnFiledNames(includColumns);
        }
        if (CollUtil.isNotEmpty(excludeColumn)) {
            excelWriterBuilder.excludeColumnFiledNames(excludeColumn);
        }

        excelWriterBuilder.registerWriteHandler(new Custemhandler());
        excelWriterBuilder.registerWriteHandler(getStyleStrategy());
        excelWriterBuilder.build().write(data, EasyExcel.writerSheet("sheet").build()).finish();
    }

    /**
     * 导出Excel
     *
     * @param response
     * @param clazz         Excel的表头对象
     * @param data          Excel的内容集合
     * @param fileName      文件名
     * @param includeColumn 过滤包含的表头列
     * @throws Exception
     */
    public static void downLoadExcel(HttpServletResponse response, Class<?> clazz, List<?> data, String fileName, Collection<String> includeColumn) throws Exception {

        downLoadExcelDynamicInclude(response, clazz, data, fileName,
                CollUtil.isNotEmpty(includeColumn) ? includeColumn.toArray(new String[]{}) : null);


//        response.setContentType("application/vnd.ms-excel");
//        response.setCharacterEncoding("utf-8");
//        response.setHeader("Content-disposition", "attachment;filename=" + URLEncoder.encode(fileName, "UTF-8") + ".xlsx");
//        ExcelWriterBuilder excelWriterBuilder = EasyExcel.write(response.getOutputStream(), clazz);
//        excelWriterBuilder.useDefaultStyle(false);
//        if (CollectionUtils.isNotEmpty(includeColumn)) {
//            excelWriterBuilder.includeColumnFiledNames(includeColumn);
//        }
//        excelWriterBuilder.build().write(data, EasyExcel.writerSheet("sheet").build()).finish();
    }

    /**
     * 获取ExcelWriterBuilder对象，用于自定义Excel设置，例如样式、列、行等等相关设置
     *
     * @param response 响应对象
     * @param fileName 下载文件名
     * @return
     * @throws Exception
     */
//	public static ExcelWriterBuilder getExcelWriterBuilder(HttpServletResponse response, String fileName, Class<?> clazz) {
//		setResponse(response, fileName);
//		try {
//			return EasyExcel.write(response.getOutputStream(), clazz);
//		} catch (IOException e) {
//			throw new RuntimeException(e.getMessage());
//		}
//	}
    public static void setResponse(HttpServletResponse response, String fileName) {
        response.setContentType("application/vnd.ms-excel");
        response.setCharacterEncoding("utf-8");
        String downloadFileName = null;
        try {
            downloadFileName = URLEncoder.encode(fileName, "UTF-8").replaceAll("\\+", "%20");
        } catch (UnsupportedEncodingException e) {
            throw new RuntimeException(e.getMessage());
        }
        response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + downloadFileName + ".xlsx");
    }


    /**
     * Excel导入监听
     *
     * @param <T>
     */
    public static class ExcelEventListener<T> extends AnalysisEventListener<T> {

        /**
         * 数据容器
         */
        List<T> dataContainer = CollUtil.newArrayList();

        final int BATCH_COUNT = 3000;

        /**
         * 回调函数接口
         */
        private ExcelEventHandler<T> excelEventHandler;

        public ExcelEventListener(ExcelEventHandler<T> excelEventHandler) {
            this.excelEventHandler = excelEventHandler;
        }

        @Override
        public void invoke(T t, AnalysisContext analysisContext) {
            log.info("Excel解析到一条数据：{}", t);
            dataContainer.add(t);
            if (dataContainer.size() >= BATCH_COUNT) {
                log.info("数据累计达到{}条，触发执行回调函数", BATCH_COUNT);
                excelEventHandler.complated(dataContainer);
                dataContainer.clear();
            }
        }

        @Override
        public void doAfterAllAnalysed(AnalysisContext analysisContext) {
            if (CollUtil.isNotEmpty(dataContainer)) {
                log.info("数据未达到{}条，默认执行回调函数", BATCH_COUNT);
                excelEventHandler.complated(dataContainer);
            }
            dataContainer.clear();
        }
    }

    public interface ExcelEventHandler<T> {
        /**
         * Excel读取数据完成的回到函数
         */
        void complated(List<T> batchData);
    }


    public static <T> List<T> readToList(File file, Class<T> tClass) {
        List<T> list = new ArrayList<>();
        EasyExcel.read(file, tClass, new AnalysisEventListener<T>() {

            /**
             * When analysis one row trigger invoke function.
             *
             * @param data    one row value. Is is same as {@link AnalysisContext#readRowHolder()}
             * @param context
             */
            @Override
            public void invoke(T data, AnalysisContext context) {
                list.add(data);
            }

            /**
             * if have something to do after all analysis
             *
             * @param context
             */
            @Override
            public void doAfterAllAnalysed(AnalysisContext context) {

            }
        }).sheet().doRead();
        return list;
    }

    public static <T> List<T> readToList(String fileName, Class<T> tClass) {
        return readToList(FileUtil.newFile(fileName), tClass);
    }

    public static List<Map<Integer, String>> readToList(String fileName) {
        return readToList(FileUtil.newFile(fileName));
    }

    public static List<Map<Integer, String>> readToList(File file) {
        List<Map<Integer, String>> list = new ArrayList<>();

        EasyExcel.read(file, new AnalysisEventListener<Map<Integer, String>>() {

            /**
             * When analysis one row trigger invoke function.
             *
             * @param data    one row value. Is is same as {@link AnalysisContext#readRowHolder()}
             * @param context
             */
            @Override
            public void invoke(Map<Integer, String> data, AnalysisContext context) {
                list.add(data);
            }

            /**
             * if have something to do after all analysis
             *
             * @param context
             */
            @Override
            public void doAfterAllAnalysed(AnalysisContext context) {

            }
        }).sheet().doRead();
        return list;
    }

//	public static OutputStream getWriteOutputStream(List<T> dataList, Class<T> clazz){
//		ByteArrayOutputStream os = new ByteArrayOutputStream();
//		ExcelWriter excelWriter = EasyExcel.write().head(clazz).file(os).build();
//		WriteSheet writeSheet = EasyExcel.writerSheet().build();
//		excelWriter.write(dataList, writeSheet);
//		//一定要进行关闭 才能获取os
//		excelWriter.finish();
//		OutputStream outputStream = excelWriter.writeContext().writeWorkbookHolder().getOutputStream();
//
//		return outputStream;
//	}

    public static <T> List<String> getTitles(Class<T> clazz, String... excludeField) {
        List<String> excludeFields = ArrayUtil.isEmpty(excludeField) ? CollUtil.newArrayList() : CollUtil.newArrayList(excludeField);
        Field[] declaredFields = clazz.getDeclaredFields();
        List<String> fieldNames = new ArrayList<>(declaredFields.length);
        for (Field field : declaredFields) {
            if (field.isAnnotationPresent(ExcelProperty.class)) {
                String fieldName = field.getName();
                if (!excludeFields.contains(fieldName)) {
                    fieldNames.add(fieldName);
                }
            }
        }
        return fieldNames;
    }


    public static <T> List<List<String>> generateHeader(Class<T> clazz) {
        return generateHeader(getTitles(clazz));
    }

    /**
     * 只支持一级标题
     *
     * @return
     */
    public static List<List<String>> generateHeader(List<String> titles) {
        List<List<String>> list = new ArrayList<>();
        for (String title : titles) {
            list.add(new ArrayList<>(Arrays.asList(title)));
        }
        //创建一个一级标题
        //创建一个二级标题
//		list.add(createHead("标题2-1", "标题2-2"));
//		list.add(createHead("标题3-1", "标题3-2"));
//		//创建一个三级标题
//		list.add(createHead("标题4-1", "标题4-2","标题4-3"));
        return list;
    }

    /**
     * 下载，可自定义表头
     *
     * @param response 响应对象
     * @param data     原始数据
     * @param titles   标题
     * @param fileName
     * @throws Exception
     */
    public static void downLoadExcelCustomizeHeader(HttpServletResponse response, List<?> data, Class<?> clazz, List<String> titles, List<String> includColumns, String fileName) throws Exception {
        settingResponse(response, fileName);
        downLoadExcelCustomizeHeader(response.getOutputStream(), data, clazz, titles, includColumns, fileName);
    }

    /**
     * 下载，可自定义表头
     *
     * @param outputStream 输出流
     * @param data         原始数据
     * @param titles       标题
     * @throws Exception
     */
    public static void downLoadExcelCustomizeHeader(OutputStream outputStream, List<?> data, Class<?> clazz, List<String> titles, List<String> includColumns, String fileName) throws Exception {
        ExcelWriterBuilder excelWriterBuilder = EasyExcel.write(outputStream, clazz);
        excelWriterBuilder.useDefaultStyle(false);
        if (CollUtil.isNotEmpty(includColumns)) {
            excelWriterBuilder.includeColumnFiledNames(includColumns);
        }
        excelWriterBuilder.head(generateHeader(titles));
        excelWriterBuilder.automaticMergeHead(false);
        excelWriterBuilder.registerWriteHandler(new Custemhandler());
        excelWriterBuilder.registerWriteHandler(getStyleStrategy());
        excelWriterBuilder.build().write(data, EasyExcel.writerSheet("sheet").build()).finish();
    }

    /**
     * 下载，可自定义表头
     *
     * @param response 响应对象
     * @param titles   标题
     * @param data     原始数据
     * @param fileName
     * @throws Exception
     */
    public static void downLoadExcelCustomizeHeader(HttpServletResponse response, List<String> titles, List<List<String>> data, String fileName) throws Exception {
        settingResponse(response, fileName);
        downLoadExcelCustomizeHeader(response.getOutputStream(), titles, data);
    }

    /**
     * 下载，可自定义表头
     *
     * @param outputStream 输出流
     * @param titles       标题
     * @param data         原始数据
     * @throws Exception
     */
    public static void downLoadExcelCustomizeHeader(OutputStream outputStream, List<String> titles, List<List<String>> data) throws Exception {
        downLoadExcelMoreCustomizeHeader(outputStream, generateHeader(titles), data);
    }

    /**
     * 下载，可自定义表头
     *
     * @param outputStream 输出流
     * @param titles       标题
     * @param data         原始数据
     * @throws Exception
     */
    public static void downLoadExcelMoreCustomizeHeader(OutputStream outputStream, List<List<String>> titles, List<List<String>> data) throws Exception {
        ExcelWriterBuilder excelWriterBuilder = EasyExcel.write(outputStream);
        excelWriterBuilder.useDefaultStyle(false);
        excelWriterBuilder.head(titles);
        excelWriterBuilder.automaticMergeHead(false);
        excelWriterBuilder.registerWriteHandler(new Custemhandler());
        excelWriterBuilder.registerWriteHandler(getStyleStrategy());
        excelWriterBuilder.build().write(data, EasyExcel.writerSheet("sheet").build()).finish();
    }

    /**
     * 设置下载响应对象
     *
     * @param response
     * @param fileName
     */
    public static void settingResponse(HttpServletResponse response, String fileName) throws Exception {
        response.setContentType("application/vnd.ms-excel");
        response.setCharacterEncoding("utf-8");
        response.setHeader("Content-disposition", "attachment;filename=" + URLEncoder.encode(fileName, "UTF-8") + ".xlsx");
    }


    public static void main(String[] args) throws Exception {
//		File file = FileUtil.file(FileUtil.getUserHomeDir(), "test-easyexcel.xlsx");
//		file.createNewFile();
//		List<List<String>> titles = Arrays.asList(
//				CollUtil.newArrayList("测试标题2","测试标题23","测试标题24","测试标题25"),
//				CollUtil.newArrayList("测试标题2","测试标题3","测试标题4","测试标题5"),
//				CollUtil.newArrayList("测试标题2","测试标题23","测试标题24","QQ"),
//				CollUtil.newArrayList("测试标题2","测试标题23","测试标题24","测试标题4"),
//				CollUtil.newArrayList("测试标题2","测试标题23","测试标题24","测试标题5"),
//				CollUtil.newArrayList("测试标题2","测试标题23","测试标题24","测试标题6"));
//
//		List<List<String>> datas = CollUtil.newArrayList();
//		List<String> data1 = CollUtil.newArrayList("1测试1", "1测试2", "ts111111t", "1测试4", "1测试5", "1测试6");
//		datas.add(data1);
//		List<String> data2 = CollUtil.newArrayList("2测试1", "2测试2", "awwww", "2测试4", "2测试5", "2测试6");
//		datas.add(data2);
//		List<String> data3 = CollUtil.newArrayList("3测试1", "3测试2", "t", "3测试4", "3测试5", "3测试6");
//		datas.add(data3);
//		System.out.println(file.getPath());
//		downLoadExcelMoreCustomizeHeader(new FileOutputStream(file.getPath()), titles,datas);

        File file = FileUtil.file(FileUtil.getUserHomeDir(), "test-easyexcel.xlsx");
        file.createNewFile();
        List<DetailRecordVO> list = CollUtil.newArrayList();
        for (int i = 0; i < 20; i++) {
            DetailRecordVO vo = new DetailRecordVO();
            vo.setId("1--" + i);
            vo.setName("2--" + i);
            vo.setNum("3--" + i);
            list.add(vo);
        }
        downLoadExcelDynamic(FileUtil.getOutputStream(file), DetailRecordVO.class, list);
    }

    /**
     * <p>主要用于旧版数据格式的支持</p>
     *
     * @param response
     * @param header
     * @param data
     * @param fileName
     * @throws Exception
     */
    public static void downLoadExcelCustomizeHeaderOld(HttpServletResponse response, String header, List<Map<String, Object>> data, String fileName) throws Exception {
        settingResponse(response, fileName);

//		"{\"sorts\":1,\"field\":\"phone\",\"status\":true,\"label\":\"电话号码\"}," +
        if (StrUtil.isNotBlank(header)) {
            List<String> headList = CollUtil.newArrayList();
            List<String> fieldList = CollUtil.newArrayList();

            JSONArray headJsonArray = JSONUtil.parseArray(header);
            for (Object o : headJsonArray) {
                JSONObject headJson = (JSONObject) o;
                Boolean status = headJson.getBool("status");
                if (status == null || status) {
                    headList.add(headJson.getStr("label"));
                    fieldList.add(headJson.getStr("field"));
                }
            }

            List<List<String>> dataList = CollUtil.newArrayList();
            if (CollUtil.isNotEmpty(data)) {
                for (Map<String, Object> dataMap : data) {
                    List<String> rowList = CollUtil.newArrayList();
                    for (String field : fieldList) {
                        rowList.add(getObjectString(dataMap.get(field)));
                    }
                    dataList.add(rowList);
                }
            }
            downLoadExcelCustomizeHeader(response.getOutputStream(), headList, dataList);
        }
    }

    private static String getObjectString(Object o) {
        if (o == null) return "";
        if (o instanceof Date) {
            return DateUtil.formatDate((Date) o);
        } else if (o instanceof LocalDate) {
            return LocalDateTimeUtil.formatNormal((LocalDate) o);
        } else if (o instanceof LocalDateTime) {
            return DateUtil.format((LocalDateTime) o, DatePattern.NORM_DATETIME_PATTERN);
        }
        return o.toString();
    }


    /**
     * Excel文档的自动列宽设置
     */
    public static class Custemhandler extends AbstractColumnWidthStyleStrategy {

        private static final int MAX_COLUMN_WIDTH = 255;
        //因为在自动列宽的过程中，有些设置地方让列宽显得紧凑，所以做出了个判断
        private static final int COLUMN_WIDTH = 10;
        private Map<Integer, Map<Integer, Integer>> CACHE = new HashMap(8);

        public Custemhandler() {
        }

        @Override
        protected void setColumnWidth(WriteSheetHolder writeSheetHolder, List<CellData> cellDataList, Cell cell, Head head, Integer relativeRowIndex, Boolean isHead) {
            boolean needSetWidth = isHead || !CollUtil.isEmpty(cellDataList);
            if (needSetWidth) {
                Map<Integer, Integer> maxColumnWidthMap = (Map) CACHE.get(writeSheetHolder.getSheetNo());
                if (maxColumnWidthMap == null) {
                    maxColumnWidthMap = new HashMap(16);
                    CACHE.put(writeSheetHolder.getSheetNo(), maxColumnWidthMap);
                }

                Integer columnWidth = this.dataLength(cellDataList, cell, isHead);
                if (columnWidth >= 0) {
                    if (columnWidth > MAX_COLUMN_WIDTH) {
                        columnWidth = MAX_COLUMN_WIDTH;
                    } else {
                        if (columnWidth < COLUMN_WIDTH) {
                            columnWidth = columnWidth + 2;
                        }
                    }

                    Integer maxColumnWidth = (Integer) ((Map) maxColumnWidthMap).get(cell.getColumnIndex());
                    if (maxColumnWidth == null || columnWidth > maxColumnWidth) {
                        ((Map) maxColumnWidthMap).put(cell.getColumnIndex(), columnWidth);
                        writeSheetHolder.getSheet().setColumnWidth(cell.getColumnIndex(), columnWidth * 256);
                    }
                }
            }
        }

        private Integer dataLength(List<CellData> cellDataList, Cell cell, Boolean isHead) {
            if (isHead) {
                return cell.getStringCellValue().getBytes().length;
            } else {
                CellData cellData = (CellData) cellDataList.get(0);
                CellDataTypeEnum type = cellData.getType();
                if (type == null) {
                    return -1;
                } else {
                    switch (type) {
                        case STRING:
                            return cellData.getStringValue().getBytes().length;
                        case BOOLEAN:
                            return cellData.getBooleanValue().toString().getBytes().length;
                        case NUMBER:
                            return cellData.getNumberValue().toString().getBytes().length;
                        default:
                            return -1;
                    }
                }
            }
        }
    }


    /**
     * Excel的字体，样式，背景色的设置
     *
     * @return
     */
    public static HorizontalCellStyleStrategy getStyleStrategy() {
        // 头的策略
        WriteCellStyle headWriteCellStyle = new WriteCellStyle();
        // 背景设置为灰色
        headWriteCellStyle.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
        WriteFont headWriteFont = new WriteFont();
        headWriteFont.setFontHeightInPoints((short) 12);
        // 字体样式
        headWriteFont.setFontName("Frozen");
        headWriteCellStyle.setWriteFont(headWriteFont);
        //自动换行
        headWriteCellStyle.setWrapped(false);
        // 水平对齐方式
        headWriteCellStyle.setHorizontalAlignment(HorizontalAlignment.CENTER);
        // 垂直对齐方式
        headWriteCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);

        // 内容的策略
        WriteCellStyle contentWriteCellStyle = new WriteCellStyle();
        // 这里需要指定 FillPatternType 为FillPatternType.SOLID_FOREGROUND 不然无法显示背景颜色.头默认了 FillPatternType所以可以不指定
//        contentWriteCellStyle.setFillPatternType(FillPatternType.SQUARES);
        // 背景白色
        contentWriteCellStyle.setFillForegroundColor(IndexedColors.WHITE.getIndex());
        WriteFont contentWriteFont = new WriteFont();
        // 字体大小
        contentWriteFont.setFontHeightInPoints((short) 12);
        // 字体样式
        contentWriteFont.setFontName("Calibri");
        contentWriteCellStyle.setWriteFont(contentWriteFont);
        // 这个策略是 头是头的样式 内容是内容的样式 其他的策略可以自己实现
        return new HorizontalCellStyleStrategy(headWriteCellStyle, contentWriteCellStyle);
    }

//	private static String[] IGNORE = {"serialVersionUID"};
//	static Field[] getDeclareFields(Class<?> clazz) {
//		Field[] declaredFields = clazz.getDeclaredFields();
//		List<Field> collect = Arrays.stream(declaredFields).collect(Collectors.toList());
//		for (Field declaredField : declaredFields) {
//			for (String s : IGNORE) {
//				String name = declaredField.getName();
//				if (name.equals(s)) {
//					collect.remove(declaredField);
//					break;
//				}
//			}
//		}
//		return collect.toArray(new Field[0]);
//	}
}
